home *** CD-ROM | disk | FTP | other *** search
- /******************************************************************************
- **
- ** Folder Name: BS
- ** File Name: SayIt.c
- **
- ** Copyright: © 1993 by Siren Enterprises, all rights reserved.
- **
- ** Description: MPW Tool to send Apple Event to Lil´ BeepSay to speak a
- ** given phrase
- **
- *******************************************************************************
- ** A U T H O R I D E N T I T Y
- *******************************************************************************
- **
- ** Initials Name
- ** -------- -----------------------------------------------
- ** kw Ken Wieschhoff
- **
- *******************************************************************************
- ** R E V I S I O N H I S T O R Y
- *******************************************************************************
- **
- ** Date Time Author Description
- ** -------- ----- ------ ---------------------------------------------
- ** 06/22/93 16:42 kw 1+ Check for Apple Events via Gestalt
- ** 06/01/93 19:01 kw Original version
- **
- ******************************************************************************/
-
- #include <ToolUtils.h>
- #include <Fonts.h>
- #include <Packages.h>
- #include <Strings.h>
- #include <Resources.h>
- #include <AppleEvents.h>
- #include <Processes.h>
- #include "Utilities.h"
- #include <stdio.h>
- #include <CType.h>
- #include <string.h>
- #include <GestaltEqu.h>
- #include <CursorCtl.h>
-
- static char *usage = "# Usage - %s [-h] | [<phrase to speak>] \n";
-
- pascal Boolean SpeakIdleProc(EventRecord *event,
- long *sleepTime, RgnHandle *mouseRgn);
-
- main(int argc, char *argv[])
- {
- ProcessSerialNumber itsNumber;
- AEDesc theAddress;
- AppleEvent ourEvent,ourReply;
- Str255 textToSend = { 0 };
- Size dataSize;
- DescType theDescType;
- long errorCode;
- Str255 returnedText;
- OSErr err;
- long result;
- long parms;
- long length;
-
- // Check for AppleEvents
- if( Gestalt(gestaltAppleEventsAttr, &result) != noErr) {
- fprintf(stdout, "### Apple Events are not supported on this machine!\n");
- return 1;
- }
-
- // Check if Lil´ BeepSay is even installed.
- if (Gestalt( kBeepSaySignature, &result) != noErr) {
- fprintf(stdout, "### Lil´ BeepSay is not installed!\n");
- return 1;
- }
-
- // Parse parameters
- for (parms = 1; parms < argc; parms++) {
- length = strlen(argv[parms]);
- if (*argv[parms] != '-') {
- strcat(textToSend, argv[parms]);
- }
- // -h for help.
- else if (tolower(*(argv[parms]+1)) == 'h' && length == 2) {
- fprintf(stdout, usage, argv[0]);
- return 0;
- }
- else {
- fprintf(stderr,"### %s - \"%s\" is not an option.\n", argv[0], argv[parms]);
- fprintf(stderr, usage, argv[0]);
- return 1;
- }
- }
-
- if ( strlen( textToSend) == 0) {
- fprintf(stderr,"### Need a phrase to speak.\n");
- fprintf(stderr, usage, argv[0]);
- return 1;
- }
-
-
- // We create an Apple Event and send it to ourselves. Since we don't have a
- // handler for this it will land in the system handler we've created
- // in Lil´ BeepSay
- itsNumber.highLongOfPSN = 0;
- itsNumber.lowLongOfPSN = kCurrentProcess;
- err = AECreateDesc(typeProcessSerialNumber, (Ptr)&itsNumber,
- sizeof(ProcessSerialNumber), &theAddress);
-
- if (err) {
- fprintf(stdout,"###Could not create Apple Event Descriptor. Error = %d\n", err);
- return 1;
- }
-
- // Create the apple event
- err = AECreateAppleEvent(kBeepSaySignature, kBeepSaySpeakPhrase, &theAddress,
- kAutoGenerateReturnID, kAnyTransactionID, &ourEvent);
-
- if (err) {
- fprintf(stdout,"###Could not create Apple Event. Error = %d\n", err);
- AEDisposeDesc( &ourEvent);
- AEDisposeDesc( &theAddress);
- return 1;
- }
-
- // Set the text buffer to use
- err = AEPutParamPtr(&ourEvent, keyDirectObject, typeChar,
- (Ptr) textToSend, strlen(textToSend));
-
- if (err) {
- fprintf(stdout,"###Could not add text to Apple Event. Error = %d\n", err);
- AEDisposeDesc( &ourEvent);
- AEDisposeDesc( &theAddress);
- return 1;
- }
-
- // Send to ourselves. Since we don't handle these,
- // they'll be dispatched to the system handler in BeepSay
- err = AESend(&ourEvent, &ourReply, kAEWaitReply,
- kAEHighPriority, kAEDefaultTimeout, (IdleProcPtr) &SpeakIdleProc, nil);
-
- if (err)
- fprintf(stdout,"###Could not send Apple Event. Error = %d\n", err);
-
- // Check for an error number.
- err = AEGetParamPtr(&ourReply, keyErrorNumber, typeLongInteger,
- &theDescType, (Ptr)&errorCode, sizeof(long),
- &dataSize);
-
- if (err && err != errAEDescNotFound)
- fprintf(stdout,"###Error returned from Apple Event. Error = %d\n", err);
-
- if (!err)
- fprintf(stdout,"###Error returned from Apple Event. Error = %d\n", err);
-
-
- // try for the error string
- err = AEGetParamPtr(&ourReply, keyErrorString, typeChar, &theDescType,
- (Ptr) returnedText, 255, &dataSize);
-
- if (!err) {
- returnedText[dataSize] = '\0'; // null terminate
- fprintf(stdout,"###Error text = %s\n", returnedText);
- }
-
- AEDisposeDesc( &ourEvent);
-
- AEDisposeDesc( &theAddress);
-
- return 0;
- }
-
- pascal Boolean SpeakIdleProc(EventRecord *event,
- long *sleepTime, RgnHandle *mouseRgn)
- {
- #pragma unused (event, sleepTime, mouseRgn)
- SpinCursor(1);
- return false;
- }
-